package com.party.core.service.mall.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.mall.MallGoodsDetailReadDao;
import com.party.core.dao.write.mall.MallGoodsDetailWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.mall.MallGoodsDetail;
import com.party.core.service.mall.IMallGoodsDetailService;
import com.sun.istack.NotNull;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * Created by huangwuming on 2018/3/27/027.
 */
@Service
public class MallGoodsDetailService implements IMallGoodsDetailService{

    @Autowired
    private MallGoodsDetailWriteDao mallGoodsDetailWriteDao;
    @Autowired
    private MallGoodsDetailReadDao mallGoodsDetailReadDao;

    /**
     *
     * @param mallGoodsDetail
     * @return
     */
    @Override
    public String insert(MallGoodsDetail mallGoodsDetail) {
        BaseModel.preInsert(mallGoodsDetail);
        boolean result = mallGoodsDetailWriteDao.insert(mallGoodsDetail);
        if(result){
            return mallGoodsDetail.getId();
        }
        return mallGoodsDetail.getId();
    }

    /**
     *
     * @param mallGoodsDetail
     * @return
     */
    @Override
    public boolean update(MallGoodsDetail mallGoodsDetail) {
        return mallGoodsDetailWriteDao.update(mallGoodsDetail);
    }

    /**
     * 逻辑删除
     * @param id 实体主键
     * @return
     */
    @Override
    public boolean deleteLogic(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return mallGoodsDetailWriteDao.deleteLogic(id);
    }

    /**
     * 物理删除
     * @param id 实体主键
     * @return
     */
    @Override
    public boolean delete(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return mallGoodsDetailWriteDao.delete(id);
    }

    /**
     * 批量逻辑删除
     * @param ids 主键集合
     * @return
     */
    @Override
    public boolean batchDeleteLogic(@NotNull Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return mallGoodsDetailWriteDao.batchDeleteLogic(ids);
        }

        return false;
    }

    /**
     * 批量物理删除
     * @param ids 主键集合
     * @return
     */
    @Override
    public boolean batchDelete(@NotNull Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return mallGoodsDetailWriteDao.batchDelete(ids);
        }
        return false;
    }

    /**
     *
     * @param id 主键
     * @return
     */
    @Override
    public MallGoodsDetail get(String id) {
        return mallGoodsDetailReadDao.get(id);
    }

    @Override
    public List<MallGoodsDetail> listPage(MallGoodsDetail mallGoodsDetail, Page page) {
        return mallGoodsDetailReadDao.listPage(mallGoodsDetail,page);
    }

    @Override
    public List<MallGoodsDetail> list(MallGoodsDetail mallGoodsDetail) {

        return mallGoodsDetailReadDao.listPage(mallGoodsDetail,null);
    }

    @Override
    public List<MallGoodsDetail> batchList(@NotNull Set<String> ids, MallGoodsDetail mallGoodsDetail, Page page) {
        return null;
    }

    @Override
    public MallGoodsDetail findByGoodsId(String goodsId) {
        return mallGoodsDetailReadDao.findByGoodsId(goodsId);
    }

    @Override
    public void deleteByGoodsId(String goodsId) {
        mallGoodsDetailWriteDao.deleteByGoodsId(goodsId);
    }
}
